/*
* Copyright 2008-2023 dexian.vip. All rights reserved.
* Support: http://www.dexian.vip
* License: http://www.dexian.vip/license
*/

package ${packagePrefix}.controller;

import vip.dexian.admin.base.BaseController;

import vip.dexian.common.Message;
import jakarta.annotation.Resource;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vip.dexian.admin.enums.OperateTypeEnum;
import vip.dexian.admin.log.AdminLog;

/**
* ${modelMap.entityComment!}管理
*
* @author ${modelMap.author} ${modelMap.now}
*/
@Controller ("admin${modelMap.simpleClassName!}Controller")
@RequestMapping ("/admin/${modelMap.underlineName!}")
// TODO 代码自动生成与${modelMap.now}，代码生成完成后，请删除该TODO语句
public class ${modelMap.simpleClassName}Controller extends BaseController {

/**
* ${modelMap.entityComment!}Service
*/
@Resource (name = "${modelMap.unCapitalizeClassName}ServiceImpl")
private ${modelMap.simpleClassName}Service ${modelMap.unCapitalizeClassName}Service;

/**
* ${modelMap.entityComment!}列表页面
*
* @param searcher
*         ${modelMap.entityComment!}查询器
* @param model
*         {@link org.springframework.ui.ModelMap}
*
* @return list view
*/
@GetMapping ("/list")
@AdminLog (module = "${modelMap.unCapitalizeClassName}", description = "查看${modelMap.entityComment!}列表", type = OperateTypeEnum.LIST)
public String page (${modelMap.simpleClassName}PageSearcher searcher, ModelMap model) {

// 将searcher添加到model中
searcher.addAttribute(model);

Page
<${modelMap.simpleClassName}DTO> page = this.${modelMap.unCapitalizeClassName}Service.findPage(searcher.query());

    model.addAttribute("page", page);

    return "/admin/${module!}/${modelMap.underlineName!}/list";
    }

    /**
    * 进入${modelMap.entityComment!}保存页面
    *
    * @return save view
    */
    @GetMapping ("/save")
    public String add () {
    return "/admin/${module!}/${modelMap.underlineName!}/save";
    }

    /**
    * 保存${modelMap.entityComment!}
    *
    * @param command
    * ${modelMap.entityComment!}保存command
    *
    * @return {@link vip.dexian.common.Message}
    */
    @PostMapping ("/save")
    @ResponseBody
    @AdminLog (module = "${modelMap.unCapitalizeClassName}", description = "保存${modelMap.entityComment!}", type = OperateTypeEnum.SAVE)
    public Message save (${modelMap.simpleClassName}SaveCommand command) {

    this.${modelMap.unCapitalizeClassName}Service.save(command);

    return Message.success();
    }

    /**
    * 进入编辑页面
    * @param model
    * {@link org.springframework.ui.ModelMap}
    * @param id
    * ${modelMap.entityComment!}id
    *
    * @return update view
    */
    @GetMapping ("/update")
    public String update (Long id, ModelMap model) {
    ${modelMap.simpleClassName}DTO ${modelMap.unCapitalizeClassName}DTO = this.${modelMap.unCapitalizeClassName}Service.find(id);

    model.addAttribute("content", ${modelMap.unCapitalizeClassName}DTO);
    return "/admin/${module!}/${modelMap.underlineName!}/update";
    }

    /**
    * 更新${modelMap.entityComment!}
    *
    * @param command
    * ${modelMap.entityComment!}更新command
    *
    * @return {@link vip.dexian.common.Message}
    */
    @PostMapping ("/update")
    @ResponseBody
    @AdminLog (module = "${modelMap.unCapitalizeClassName}", description = "更新${modelMap.entityComment!}", type = OperateTypeEnum.UPDATE)
    public Message update (${modelMap.simpleClassName}UpdateCommand command) {
    this.${modelMap.unCapitalizeClassName}Service.update(command);

    return Message.success();
    }

    /**
    * 删除${modelMap.entityComment!}
    *
    * @param ids
    * id列表，客户端传递的参数为： ids=1&ids=2&ids=3
    *
    * @return {@link vip.dexian.common.Message}
    */
    @PostMapping ("/delete")
    @ResponseBody
    @AdminLog (module = "${modelMap.unCapitalizeClassName}", description = "更新${modelMap.entityComment!}", type = OperateTypeEnum.UPDATE)
    public Message delete (Long[] ids) {
    this.${modelMap.unCapitalizeClassName}Service.delete(ids);
    return Message.success();
    }

}
